/**
 * Created by gacl on 2017/9/3.
 */
$(function() {
    addTabs(({ id: '10008', title: '欢迎页', close: false, url: '/views/admin/dashboard.html' }));
    App.fixIframeCotent();
    var menus = [
        { id: "10010", text: "我的工作台", isHeader: true },
        {
            id: "10001",
            text: "基础UI",
            icon: "fa fa-circle-o",
            children: [
                { id: "10004", text: "按钮", url: "/static/superui/components/buttons.html", targetType: "iframe-tab", icon: "fa fa-square" },
                { id: "10003", text: "常用组件", url: "/static/superui/components/general.html", targetType: "iframe-tab", icon: "fa fa-list-alt" },
                { id: "10012", text: "图标库", url: "/static/superui/components/icons.html", targetType: "iframe-tab", icon: "fa fa-circle-o" },
                {
                    id: "10203",
                    text: "表单组件",
                    url: "/static/superui/forms/general.html",
                    targetType: "iframe-tab",
                    icon: "fa fa-plus-square-o"
                },
                {
                    id: "10204",
                    text: "表单扩展组件",
                    url: "/static/superui/forms/advanced.html",
                    targetType: "iframe-tab",
                    icon: "fa fa-plus-square-o"
                },
                { id: "10005", text: "Block UI", url: "/static/superui/components/blockui.html", targetType: "iframe-tab", icon: "fa fa-spinner" },
                { id: "10013", text: "sliders组件",tips:5, url: "/static/superui/components/sliders.html", targetType: "iframe-tab", icon: "fa fa-list-ol" },
                { id: "10204", text: "switch按钮", targetType: "iframe-tab", url: "/static/superui/components/bootstrapswitch.html", icon: "fa fa-toggle-on" },
                { id: "10017", text: "面板", targetType: "iframe-tab", url: "/static/superui/components/widgets.html", icon: "fa fa-circle-o" }
            ]
        },
        {
            id: "10202",
            text: "插件",
            targetType: "iframe-tab",
            icon: "fa fa-circle-o",
            children: [
                { id: "10026", text: "layer弹出层", targetType: "iframe-tab",  url: "/static/superui/components/layer.html", icon: "fa fa-circle-o" },
                { id: "10006", text: "日历选择控件", targetType: "iframe-tab", url: "/static/superui/component-extend/calendar.html", icon: "fa fa-circle-o" },
                { id: "10014", text: "时间轴", targetType: "iframe-tab", url: "/static/superui/component-extend/timeline.html", icon: "fa fa-circle-o" },
                { id: "10010", text: "页面加载效果", targetType: "iframe-tab", url: "/static/superui/component-extend/pageprogress.html", icon: "fa fa-circle-o" },
                { id: "10016", text: "树", targetType: "iframe-tab", url: "/static/superui/component-extend/jstree.html", icon: "fa fa-circle-o" },
                { id: "10014", text: "日起选择组件", targetType: "iframe-tab", url: "/static/superui/component-extend/datetimepickers.html", icon: "fa fa-calendar" },
                { id: "10242", text: "select2下拉框", targetType: "iframe-tab", url: "/static/superui/component-extend/select2.html", icon: "fa fa-circle-o" },
                { id: "10205", text: "多选框", targetType: "iframe-tab", url: "/static/superui/component-extend/bootstraptagsinput.html", icon: " fa fa-check-square-o" },
                { id: "10206", text: "多文件上传组件", targetType: "iframe-tab", url: "/static/superui/component-extend/formfileupload.html", icon: "  fa fa-circle-o " }
            ]
        },
        {
            id: "10208",
            text: "表格组件",
            icon: "fa fa-circle-o",
            children: [
                { id: "10211", text: "bootstraptable表格", targetType: "iframe-tab", url: "/static/superui/tables/basetable.html", icon: "fa fa-table" },
                { id: "10212", text: "管理表格", targetType: "iframe-tab", url: "/static/superui/tables/managetable.html", icon: "fa fa-table" },
                { id: "10213", text: "jqgrid表格", targetType: "iframe-tab", url: "/static/superui/tables/jqgrid.html", icon: "fa fa-table" }
            ]
        },
        {
            id: "20209",
            text: "布局",
            isOpen: false,
            icon: "fa fa-circle-o",
            children: [
                { id: "20214", text: "盒式布局", targetType: "blank", url: "/static/superui/layout/boxed.html", icon: "fa fa-circle-o" },
                { id: "20215", text: "自适应布局", targetType: "blank", url: "/static/superui/layout/fixed.html", icon: "fa fa-circle-o" },
                { id: "20216", text: "顶部菜单", targetType: "blank", url: "/static/superui/layout/top-nav.html", icon: "fa fa-circle-o" },
                { id: "20217", text: "左侧菜单收缩", targetType: "blank", url: "/static/superui/layout/collapsed-sidebar.html", icon: "fa fa-circle-o" }
            ]

        },
        {
            id: "30209", text: "图表", isOpen: false, icon: "fa fa-circle-o",
            children: [
                { id: "30214", text: "chart图表", targetType: "iframe-tab", url: "/static/superui/charts/chartjs.html", icon: "fa fa-circle-o" },
                { id: "30215", text: "flot图表", targetType: "iframe-tab", url: "/static/superui/charts/flot.html", icon: "fa fa-circle-o" },
                { id: "30216", text: "inline图表", targetType: "iframe-tab", url: "/static/superui/charts/inline.html", icon: "fa fa-circle-o" },
                { id: "30217", text: "morris图表", targetType: "iframe-tab", url: "/static/superui/charts/morris.html", icon: "fa fa-circle-o" },
                {
                    id: "40001",
                    text: "echart图表",
                    icon: "fa fa-circle-o",
                    children: [
                        { id: "40002", text: "折线图", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_line.html", icon: "fa fa-circle-o" },
                        { id: "40003", text: "柱状图", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_column.html", icon: "fa fa-circle-o" },
                        { id: "40004", text: "仪表盘", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_dashboard.html", icon: "fa fa-circle-o" },
                        { id: "40005", text: "热力图", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_hotMap.html", icon: "fa fa-circle-o" },
                        { id: "40006", text: "雷达图", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_radar.html", icon: "fa fa-circle-o" },
                        { id: "40007", text: "k线图", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_kLine.html", icon: "fa fa-circle-o" },
                        { id: "40008", text: "地图", targetType: "iframe-tab", url: "/static/superui/charts/echarts/echarts_map.html", icon: "fa fa-circle-o" },
                        { id: "40009", text: "更多案例", targetType: "blank", url: "http://echarts.baidu.com/examples.html", icon: "fa fa-circle-o" }
                    ]
                }
            ]
        }
    ];
    $('.sidebar-menu').sidebarMenu({ data: menus, param: { strUser: 'admin' } });
});

var vm = new Vue({
    el:'#app',
    data:{
        user:{},
        menuList:{}
    },
    created: function(){
        this.getUser();
    },
    methods: {
        /**
         * 获取菜单和权限信息
         */
        getMenuList: function () {
            $.getJSON(baseURL + "sys/menu/nav", {"token":token},function(r){
                vm.menuList = r.menuList;
                window.permissions = r.permissions;
            });
        },
        /**
         * 获取用户信息
         */
        getUser: function(){
            //使用jquery发起ajax请求
            $.ajax({
                type: "POST",
                url: baseURL+"/sys/sysUser/info",
                success: function(r){
                    console.log("index→r="+r);
                    if(r.code == 0){//成功
                        vm.user = r.user;
                    }else{
                        layerAlert(r.msg);
                    }
                }
            });
        },
        /**
         * 注销
         */
        logout: function () {
            $.ajax({
                type: "POST",
                url: baseURL + "/sys/logout",
                success: function(r){
                    //删除本地token
                    localStorage.removeItem("token");
                    //跳转到登录页面
                    location.href = '/login.html';
                }
            });
        }
    }
});